package com.yunxi.controller.otd;

import com.yunxi.core.web.ApiResult;
import com.yunxi.core.web.CurrentUser;
import com.yunxi.core.web.LoginInfo;
import com.yunxi.core.web.ResponseUtil;
import com.yunxi.otd.pojo.OtdIfProducePlanVO;
import com.yunxi.otd.pojo.OtdWeekImportVO;
import com.yunxi.otd.pojo.OtdWeekPlanDetailVO;
import com.yunxi.otd.pojo.OtdWeekPlanSingleVO;
import com.yunxi.otd.pojo.OtdWeekPlanVO;
import com.yunxi.otd.pojo.OtdWeekUploadVO;
import com.yunxi.otd.service.OtdWeekPlanAuditDubboService;
import com.yunxi.otd.service.OtdWeekPlanDubboService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 周度需求计划 前端控制器
 * </p>
 *
 * @author XUQI
 * @since 2019-05-09
 */
@RestController
@RequestMapping("/admin/otd/week/audit")
@Api(tags = "OTD:WEEKAUDIT", description = "销售预测审批")
public class OtdWeekPlanAuditController {

    private static final Logger logger = LoggerFactory.getLogger(OtdWeekPlanAuditController.class);

    @Autowired
    OtdWeekPlanDubboService otdWeekPlanDubboService;

    @Autowired
    OtdWeekPlanAuditDubboService weekPlanAuditDubboService;

    @GetMapping("/page")
    @ApiOperation(value = "主页面上传记录询")
    public ApiResult page(OtdWeekPlanVO weekPlanVO, Integer pageNum, Integer pageSize) {
        weekPlanVO.setMark("audit");
        return ResponseUtil.ok(otdWeekPlanDubboService.page(weekPlanVO, pageNum, pageSize));
    }

    @GetMapping("/detail")
    @ApiOperation(value = "查看明细")
    public ApiResult weekPlan(String year, String month, String week) {
        return ResponseUtil.ok(weekPlanAuditDubboService.findIfPlanListByWeek(year, month, week));
    }

    @PostMapping("/add/ifPlan")
    @ApiOperation(value = "新增单车")
    public ApiResult addSingle(@RequestBody OtdIfProducePlanVO planVO, @CurrentUser LoginInfo user) {
        return weekPlanAuditDubboService.addIfPlan(planVO, user);
    }

    @PostMapping("/modify/ifPlan")
    @ApiOperation(value = "编辑")
    public ApiResult modifySingle(@RequestBody OtdIfProducePlanVO planVO, @CurrentUser LoginInfo user) {
        return weekPlanAuditDubboService.modifyIfPlan(planVO, user);
    }

    @PostMapping("/remove/ifPlan")
    @ApiOperation(value = "删除周单车")
    public ApiResult removeSingle(@RequestBody String ifPlanId) {
        return weekPlanAuditDubboService.removeIfPlan(ifPlanId);
    }

    @PostMapping("/send")
    @ApiOperation(value = "周计划下发")
    public ApiResult send(@RequestBody String weekPlanId) {
        return weekPlanAuditDubboService.sendWeekPlan(weekPlanId);
    }
}
